실습: Spring Mass system#
강좌: 수치해석 프로젝트
실습#
Matrix 곱셈 연산 속도 측정#
A (\(m \times n\)), B (\(n \times l\)) 곱셈 연산을 수행할 경우
A 행렬의 row vector와 B 행렬의 column vector 가 내적한다
\(a_1*b_1 + a_2*b_2\) : 2번의 곱셈 + 1번의 덧셈
\(2n-1 \approx 2n\) 번의 연산 (덧셈 & 곱셈)
m 개의 Row 와 l 개의 column 에 대해 연산을 반복한다.
총 \(2 m \times l\times n\) 번의 연산 수행
\(2 m \times l\times n\) Floating Points OPerations (FLOP)
GEMM (General Matrix to Matrix Multiplication)
대표적인 연산 속도 측정 방법
FLOPS : Floating Points OPerations per Second
%timeit
함수를 이용해서 \(m=n=l=4096\) 인 경우 평균 연산 시간과 FLOPS를 측정하라Double precision 과 Single Precision 모두 측정하라
사용중인 CPU의 이론 성능과 비교해보자
import numpy as np
m=n=l=4096
a = np.random.rand(m, n)
b = np.random.rand(n, l)
c = np.random.rand(m, l)
t = %timeit -o c[:] = a @ b
flops = 2*m*n*l / t.average
print("Measured FLOPS : {:.4f} GFLOPS".format(flops*1e-9))
752 ms ± 46.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Measured FLOPS : 182.8540 GFLOPS
Spring Mass System#
3개의 Spring과 3개의 Mass로 구성된 System을 가정하자.
\(k_1 = 15, k_2 = 35, k_3= 25\)
\(m_1 = 2, m_2 = 1.5, m_3= 0.5\)

Fig. 6 Example of Spring-Mass System#
이 System에 y 축 방향으로 중력이 작용할 경우 평형 상태에서 변위를 구하시오
이 System이 진동할 경우 진동 주기를 구하시오.
#DIY